package bd403.Backend;

/*
 * Class to hold information about a drink before it is added to the DB
 * or the local DrinkStorage as a Drink.
 * Main author: Darren
 */

public class DrinkParams {
	private String name;
	private String comment;
	private int rating;
	private String type;
	
	/*
	 * Creates a set of data that will be attached to a Drink. After creation,
	 * name will have each word begin in upper case, while having the rest of
	 * the letters be lower case. This assumes a valid rating and type
	 */
	public DrinkParams(String name, String comment, int rating, String type) {
		this.name = formatString(name);
		this.comment = comment;
		this.rating = rating;
		this.type = type;
	}
	
	/*
	 * Method to format strings correctly.  Trims whitespace and converts to
	 * all words in a string to have an upper case first character and the 
	 * rest lower case.
	 */
	private String formatString(String name) {
		if (name.length() == 0)
			return name;
		String[] trimmedLower = name.trim().toLowerCase().split("[ \t]+");
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < trimmedLower.length; i++) {
			String word = trimmedLower[i];
			sb.append(word.substring(0,1).toUpperCase());
			sb.append(word.substring(1,word.length()));
			sb.append(" ");
		}
		return sb.toString().trim();
	}
	
	/* Returns the name of this drink.
	 */
	public String getName() {
		return name;
	}
	
	/* Returns a String representation of a comment for this drink.
	 */
	public String getComment() {
		return comment;
	}
	
	/* Returns an int representing the rating for this drink.
	 */
	public int getRating() {
		return rating;
	}
	
	/* Returns a String representing the type of this drink (Beer, Wine, Mixed).
	 */
	public String getType() {
		return type;
	}
}
